package com.fili.gui.view;

import com.fili.core.storage.StorageItem;
import com.fili.gui.components.ActiveCell;
import com.fili.gui.components.Bevel;
import com.fili.gui.components.DisplayCell;

import javax.swing.*;
import java.awt.*;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 14, 2006
 * Time: 10:53:19 PM
 */
public class ISPMView extends DataView
{
    private DisplayCell edProbe0;
    private DisplayCell edProbe1;
    private DisplayCell edProbe2;
    private DisplayCell edProbe3;
    private DisplayCell edProbe4;
    private DisplayCell edProbe5;
    private DisplayCell edProbe6;
    private DisplayCell edProbe7;
    private DisplayCell edAvgAir;
    private DisplayCell edAvgWood;
    private DisplayCell edCurrentHumid;
    private DisplayCell edWantedTemp;
    private ActiveCell edFanOn;
    private ActiveCell edHeatOn;

    private JLabel lblTitle;

    public ISPMView()
    {
        setSize(237, 286);
        setPreferredSize(new Dimension(237, 286));
        setLayout(null);

        JLabel lbl = new JLabel("Sonda 1");
        lbl.setBounds(7, 51, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 2");
        lbl.setBounds(135, 51, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 1");
        lbl.setBounds(7, 99, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 2");
        lbl.setBounds(135, 99, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 3");
        lbl.setBounds(7, 123, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 4");
        lbl.setBounds(135, 123, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 5");
        lbl.setBounds(7, 147, 52, 13);
        add(lbl);

        lbl = new JLabel("Sonda 6");
        lbl.setBounds(135, 147, 52, 13);
        add(lbl);

        lbl = new JLabel("Medie aer");
        lbl.setBounds(7, 195, 68, 13);
        add(lbl);

        lbl = new JLabel("Medie lemn");
        lbl.setBounds(7, 219, 68, 13);
        add(lbl);

        lbl = new JLabel("Umid. aer");
        lbl.setBounds(119, 195, 68, 13);
        add(lbl);

        lbl = new JLabel("Temp. dorita");
        lbl.setBounds(119, 219, 68, 13);
        add(lbl);

        lbl = new JLabel("Ventilare");
        lbl.setBounds(7, 259, 68, 13);
        add(lbl);

        lbl = new JLabel("Incalzire");
        lbl.setBounds(119, 259, 68, 13);
        add(lbl);

        lbl = new JLabel("Sonde aer:");
        lbl.setBounds(7, 31, 68, 13);
        add(lbl);

        Bevel bvl = new Bevel();
        bvl.setBounds(66, 38, 161, 2);
        add(bvl);

        lbl = new JLabel("Sonde lemn:");
        lbl.setBounds(7, 80, 59, 13);
        add(lbl);

        bvl = new Bevel();
        bvl.setBounds(74, 87, 153, 2);
        add(bvl);

        lbl = new JLabel("Medii:");
        lbl.setBounds(7, 175, 36, 13);
        add(lbl);

        bvl = new Bevel();
        bvl.setBounds(42, 182, 185, 2);
        add(bvl);

        lblTitle = new JLabel("");
        lblTitle.setBounds(10, 8, 215, 13);
        lblTitle.setFont(lbl.getFont().deriveFont(Font.BOLD));
        lblTitle.setHorizontalAlignment(JLabel.CENTER);
        add(lblTitle);

        edProbe0 = new DisplayCell(-1);
        edProbe0.setBounds(66, 48, 41, 21);
        add(edProbe0);

        edProbe1 = new DisplayCell(-1);
        edProbe1.setBounds(186, 48, 41, 21);
        add(edProbe1);

        edProbe2 = new DisplayCell(-1);
        edProbe2.setBounds(66, 96, 41, 21);
        add(edProbe2);

        edProbe3 = new DisplayCell(-1);
        edProbe3.setBounds(186, 96, 41, 21);
        add(edProbe3);

        edProbe4 = new DisplayCell(-1);
        edProbe4.setBounds(66, 120, 41, 21);
        add(edProbe4);

        edProbe5 = new DisplayCell(-1);
        edProbe5.setBounds(186, 120, 41, 21);
        add(edProbe5);

        edProbe6 = new DisplayCell(-1);
        edProbe6.setBounds(66, 144, 41, 21);
        add(edProbe6);

        edProbe7 = new DisplayCell(-1);
        edProbe7.setBounds(186, 144, 41, 21);
        add(edProbe7);

        edAvgAir = new DisplayCell(-1);
        edAvgAir.setBounds(66, 192, 41, 21);
        add(edAvgAir);

        edAvgWood = new DisplayCell(-1);
        edAvgWood.setBounds(66, 216, 41, 21);
        add(edAvgWood);

        edCurrentHumid = new DisplayCell(-1);
        edCurrentHumid.setBounds(186, 192, 41, 21);
        add(edCurrentHumid);

        edWantedTemp = new DisplayCell(-1);
        edWantedTemp.setBounds(186, 216, 41, 21);
        add(edWantedTemp);

        edFanOn = new ActiveCell("Pornit");
        edFanOn.setBounds(66, 256, 41, 21);
        add(edFanOn);

        edHeatOn = new ActiveCell("Oprit", false);
        edHeatOn.setBounds(186, 256, 41, 21);
        add(edHeatOn);
    }

    public void update(StorageItem item)
    {
        edProbe0.setValue(item.probes[StorageItem.PROBE_AIR_TEMP + 0]);
        edProbe1.setValue(item.probes[StorageItem.PROBE_AIR_TEMP + 1]);

        edProbe2.setValue(item.probes[StorageItem.PROBE_WOOD_TEMP + 0]);
        edProbe3.setValue(item.probes[StorageItem.PROBE_WOOD_TEMP + 1]);
        edProbe4.setValue(item.probes[StorageItem.PROBE_WOOD_TEMP + 2]);
        edProbe5.setValue(item.probes[StorageItem.PROBE_WOOD_TEMP + 3]);
        edProbe6.setValue(item.probes[StorageItem.PROBE_WOOD_TEMP + 4]);
        edProbe7.setValue(item.probes[StorageItem.PROBE_WOOD_TEMP + 5]);

        edAvgAir.setValue(item.avgAir);
        edAvgWood.setValue(item.avgWood);
        edCurrentHumid.setValue(item.currentHumid);
        edWantedTemp.setValue(item.wantedTemp);

        edFanOn.setActive(item.bFan);
        edHeatOn.setActive(item.bHeat);

    }


    public void setID(int ID)
    {
        lblTitle.setText("Uscator " + (ID + 1));
    }
}
